﻿
namespace Architecture.Common
{
    /// <summary>
    /// 公共扩展类(定义扩展方法)
    /// 用This作为类型扩展的关键词
    /// 类和方法都是静态的
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// 扩展字符串转数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ToIn32(this string? value)
        {
            if(value == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(value);
            }
        }
        /// <summary>
        /// 根据身份证计算出生年月日
        /// </summary>
        /// <param name="cardid"></param>
        /// <returns></returns>
        public static string GetBirthCardId(this string cardId)
        {
            //130634 20041115 3135
            string result = cardId.Substring(6, 8);
            return result;
            //string idstring = "130634200411153135".GetBirthCardId();
        }
        /// <summary>
        /// 时间格式转化
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string GetTime(this DateTime time)
        {
            return time.ToString("YYYY-MM-DD");
        }
    }
}
